<%-- 
    Document   : lab
    Created on : 2019-2-17, 16:53:57
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>        
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script type="text/javascript">
            
            $(document).ready(function() {
                
            });

            function newUser() {

                var dd = $('#dg').datagrid('getData')
                $('#dlg').dialog('open').dialog('setTitle', '新课程');                
                $('#fm').form('clear');
                $('#cc1Semester').combobox('select','1');
                
                $('#evalmethod1').radiobutton('check');
                //$('#className').textbox('setText', teachclassname);
                //$('#teachclassid').val(teachclassid)
                //$('#no').val(dd.total + 1);
                //$('#duedate').datebox('setValue', '6/1/2012');	// set datebox value
                url = '../../servlet/course/SaveCourse';
            }

            function destroyUser() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('Confirm', '您确定要删除该课程吗? 删除课程将相关实验、作业等信息一起删除。', function(r) {
                        if (r) {
                            $.post('../../servlet/course/DestroyCourse', {id: row.id}, function(result) {
                                if (result.success) {
                                    $('#dg').datagrid('reload');    // reload the user data
                                } else {
                                    $.messager.show({// show error message
                                        title: 'Error',
                                        msg: result.errorMsg
                                    });
                                }
                            }, 'json');
                        }
                    });
                }
            }
            function editUser() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $('#dlg').dialog('open').dialog('setTitle', '编辑');                    
                    var semesterText =row.coursesemester;
                    $('#cc1Semester').combobox('setText',semesterText);
                    $('#id').textbox('setValue',row.id);
                    $('#fm').form('load', row);
                    url = '../../servlet/course/EditCourse?id=' + row.id;
                }
            }
            function refreshUser(){
                $('#dg').datagrid('reload');    // reload the user data
            }
            function saveUser() {
                $('#fm').form('submit', {
                    url: url,
                    onSubmit: function(param) {
                        var cc1SemesterText = $('#cc1Semester').combobox('getText');
                        param.semester1 = cc1SemesterText;
                        //$(this).queryParams={semesterText:cc1SemesterText};
                        return $(this).form('validate');
                        
                    },
                    success: function(result) {
                        var result = eval('(' + result + ')');
                        if (result.errorMsg) {
                            $.messager.show({
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        } else {
                            $('#dlg').dialog('close');        // close the dialog
                            $('#dg').datagrid('reload');    // reload the user data
                        }
                    }
                });
            }

        </script>
    </head>
    <body>
        <script type="text/javascript">
            var url;
            var teachclassid = <%=request.getParameter("id")%>
            var teachclassname = '<%=request.getParameter("text")%>';
            var courseName = '<%=session.getAttribute("courseName")%>';
            //alert(teachclassid+teachclassname);
            var teachclassno;
        </script>
        <table id="dg" title="课程管理" class="easyui-datagrid"
               url="../../servlet/course/GetCourses"
               toolbar="#toolbar"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>
                    <th field="id" width="50">ID</th>                    
                    <th field="coursename" width="150">名称</th>
                    <th field="credit" width="50">学分</th>
                    <th field="evalmethod" width="50">考核方式</th>
                    <th field="teachclassno" width="50">教学班号</th>
                    <th field="coursesemester" width="50">学期</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">增加</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="refreshUser()">刷新</a>
        </div>
        <div id="dlg" class="easyui-dialog" style="width:500px;height:350px;padding:5px 5px"
             closed="true" buttons="#dlg-buttons">
            <div class="ftitle">课程信息</div>
            <form id="fm" method="post">
                <input type ="hidden" class="easyui-textbox" name="ID" id="id"/>
                <input type="hidden" name="teachclassid" id="teachclassid"/>
                <div class="fitem">
                    <label>课程名称:</label>
                    <input id='coursename' name="coursename" class="easyui-textbox" required="true" >
                </div>
                <div class="fitem">
                    <label>学分:</label>
                    <input id="credit" name="credit" class="easyui-numberbox" required="true" data-options="min:2,precision:0">
                </div>
                <div class="fitem" class="easyui-validatebox" required="true">
                    <label>考查方式:</label>                    
                        <input class="easyui-radiobutton" id="evalmethod1" data-options="checked:true"  labelPosition="after" name="evalmethod" value="考试" label="考试"> 
                        |
                        <input class="easyui-radiobutton" id = "evalmethod2" name="evalmethod" labelPosition="after" value="考查" label="考查">                                      
                     
                </div>
                <div class="fitem">
                    <label>教学班号:</label>
                    <input id="teachclassno" class="easyui-textbox" name="teachclassno"  required="required">
                </div>
                <div class="fitem">
                    <label>学期:</label>
                    <input id="cc1Semester" class="easyui-combobox" name="semester"   
                               data-options="valueField:'id',textField:'text',
                               url:'../../servlet/util/Last5Semester'"/>
                </div>
            </form>
        </div>
        <div id="dlg-buttons">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </div>
        <style type="text/css">
		#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
		.fitem input{
			width:160px;
		}
	</style>
    </body>
</html>
